package com.zbkj.crmeb.member.controller;


import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.common.CommonPage;
import com.common.PageParamRequest;
import com.crmeb.core.common.CommonResult;
import com.crmeb.core.exception.ExceptionCodeEnum;
import com.zbkj.crmeb.member.model.MerchantMemberType;
import com.zbkj.crmeb.member.service.IMerchantMemberTypeService;
import com.zbkj.crmeb.member.vo.MerchantMemberStyleVO;
import com.zbkj.crmeb.member.vo.MerchantMemberTypeVO;
import com.zbkj.crmeb.merchant.admin.controller.AdminBaseController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 商户会员类型表 前端控制器
 * </p>
 *
 * @author xx
 * @since 2022-05-10
 */
@RestController
@RequestMapping("api/admin/mer/member/type")
@Api(tags = "商户会员类型")
public class MerchantMemberTypeController extends AdminBaseController {

    @Autowired
    private IMerchantMemberTypeService merchantMemberTypeService;

    @ApiOperation(value = "商户会员类型查询")
    @RequestMapping(value = "/getMemberBenefits", method = RequestMethod.POST)
    public CommonResult<CommonPage<MerchantMemberType>> getMemberBenefits(@Validated PageParamRequest pageParamRequest, HttpServletRequest servletRequest){
        return CommonResult.success(merchantMemberTypeService.getMemberType(getMerId(servletRequest), pageParamRequest));
    }

    @ApiOperation(value = "商户会员类型编辑")
    @RequestMapping(value = "/updMemberBenefits", method = RequestMethod.POST)
    public CommonResult<Object> updMemberBenefits(@RequestBody @Validated MerchantMemberTypeVO merchantMemberTypeVO, HttpServletRequest servletRequest){
        return merchantMemberTypeService.updMemberType(merchantMemberTypeVO) ? CommonResult.success() : CommonResult.failed();
    }

    @ApiOperation(value = "商户会员协议编辑")
    @ApiImplicitParam(name="membershipAgreement", value="会员协议")
    @RequestMapping(value = "/updMembershipAgreement", method = RequestMethod.POST)
    public CommonResult<Object> updMembershipAgreement(@RequestParam String membershipAgreement, HttpServletRequest servletRequest){
        return merchantMemberTypeService.updMembershipAgreement(getMerId(servletRequest), membershipAgreement) ? CommonResult.success() : CommonResult.failed();
    }

    @ApiOperation(value = "商户会员协议查询")
    @RequestMapping(value = "/getMembershipAgreement", method = RequestMethod.GET)
    public CommonResult<String> getMembershipAgreement(HttpServletRequest servletRequest){
        return CommonResult.success(merchantMemberTypeService.getMembershipAgreement(getMerId(servletRequest)), ExceptionCodeEnum.SUCCESS.getMessage());
    }

    @ApiOperation(value = "商户会员样式编辑")
    @RequestMapping(value = "/updMemberStyle", method = RequestMethod.POST)
    public CommonResult<Object> updMemberStyle(@RequestBody MerchantMemberStyleVO merchantMemberStyleVO, HttpServletRequest servletRequest){
        return merchantMemberTypeService.updMemberStyle(getMerId(servletRequest), merchantMemberStyleVO) ? CommonResult.success() : CommonResult.failed();
    }

    @ApiOperation(value = "商户会员样式查询")
    @RequestMapping(value = "/getMemberStyle", method = RequestMethod.GET)
    public CommonResult<MerchantMemberStyleVO> getMemberStyle(HttpServletRequest servletRequest){
        return CommonResult.success(merchantMemberTypeService.getMemberStyle(getMerId(servletRequest)));
    }


    @ApiOperation(value = "查询商户是否有用户开通会员")
    @RequestMapping(value = "/getMemberByMerId", method = RequestMethod.GET)
    public CommonResult<Object> getMemberByMerId(HttpServletRequest servletRequest){
        return merchantMemberTypeService.getMemberByMerId(getMerId(servletRequest)) ? CommonResult.success() : CommonResult.failed();
    }
}

